package io.finer.erp.jeecg.bas.service.impl;

import io.finer.erp.jeecg.bas.entity.ZrkOrderProcess;
import io.finer.erp.jeecg.bas.entity.ZzDeviceType;
import io.finer.erp.jeecg.bas.mapper.ZrkOrderProcessMapper;
import io.finer.erp.jeecg.bas.service.IZrkOrderProcessService;
import io.finer.erp.jeecg.bas.service.IZzDeviceTypeService;

import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.api.client.util.Maps;
import com.google.common.collect.Lists;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: 车间任务单工序机器分配
 * @Author: jeecg-boot
 * @Date:   2020-09-02
 * @Version: V1.0
 */
@Service
public class ZrkOrderProcessServiceImpl extends ServiceImpl<ZrkOrderProcessMapper, ZrkOrderProcess> implements IZrkOrderProcessService {
	
	@Autowired
	private ZrkOrderProcessMapper zrkOrderProcessMapper;
	@Autowired
	private IZzDeviceTypeService deviceTypeService;
	
	@Override
	public List<ZrkOrderProcess> selectByMainId(String mainId) {
		return zrkOrderProcessMapper.selectByMainId(mainId);
	}

	@Override
	public List<ZrkOrderProcess> getProcessByOrderId(String orderId) {
		return this.baseMapper.getProcessByOrderId(orderId);
	}

	@Override
	public List<ZrkOrderProcess> getProcessByOrderAndProcess(String orderId, String type) {
		List<ZrkOrderProcess> processList = this.getProcessByOrderId(orderId);
		if(processList == null || processList.size() == 0) {
			return processList;
		}
		List<ZzDeviceType> dtList = deviceTypeService.list();
		Map<String, String> typeMap = Maps.newHashMap();
		for (ZzDeviceType zzDeviceType : dtList) {
			if(zzDeviceType.getDeviceTpyeName().contains(type)) {
				typeMap.put(zzDeviceType.getId(), zzDeviceType.getId());
			}
		}
		List<ZrkOrderProcess> resultList = Lists.newArrayList();
		for (ZrkOrderProcess process : processList) {
			if(typeMap.get(process.getProcessId()) != null) {
				resultList.add(process);
			}
		}
		return resultList;
	}
}
